package com.wzx.data.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.wzx.basics.baseVo.PageVo;
import com.wzx.basics.baseVo.Result;
import com.wzx.basics.utils.PageUtil;
import com.wzx.basics.utils.ResultUtil;
import com.wzx.data.entity.Subject;
import com.wzx.data.utils.NullUtils;
import com.wzx.data.entity.Chapter;
import com.wzx.data.service.IChapterService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wzx.data.vo.ChapterVo;
import com.wzx.data.vo.SubjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author wzx
 */
@Slf4j
@RestController
@Api(tags = "章节管理接口")
@RequestMapping("/wzx/chapter")
@Transactional
public class ChapterController {

    @Autowired
    private IChapterService chapterService;

    @ApiOperation("大纲列表")
    @GetMapping("/getNestedTreeList")
    public Result getTreeList( String courseId) {
        List<ChapterVo> list = chapterService.getTreeList(courseId);
        return ResultUtil.data(list);
    }

    @ApiOperation("新增")
    @PostMapping("save")
    public Result save(Chapter chapter) {
        chapterService.save(chapter);
        return ResultUtil.success();
    }

    @ApiOperation("根据Id获取")
    @GetMapping("getById/{id}")
    public Result get(@PathVariable String id) {
        Chapter chapter = chapterService.getById(id);
        return ResultUtil.data(chapter);
    }

    @ApiOperation("修改")
    @PostMapping("update")
    public Result update(Chapter chapter) {
        chapterService.updateById(chapter);
        return ResultUtil.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/deleteById")
    public Result deleteById(String id) {
        chapterService.removeById(id);
        return ResultUtil.success();
    }


}
